package com.zx.mes.webmvc.hyl.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;

/**
 * 前端控制器测试
 *
 * @author huayunlong
 * @date 2018-8-13
 */
@RestController
public class HelloController {

    @GetMapping("/hi")
    public String hi() {
        return "hi:god";
    }

    @GetMapping("/excep")
    public String exception() throws Exception {

        int i = 0;
        if (i == 0) {
            throw new Exception("神一般的异常!");
        }

        return "exception";
    }

    @GetMapping("/excep2")
    public String exception2() {

        int i = 0;
        if (i == 0) {
            int m = i / 0;
        }

        return "exception";
    }

    /**
     * 使用try catch 手动处理异常,不会被ExceptionControllerAdvice 捕获
     *
     * @return
     */
    @GetMapping("/excep3")
    public String exception3() {

        int i = 0;
        if (i == 0) {
            try {
                throw new SQLException("sql 语句异常");
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        return "exception";
    }

    /**
     * 使用try catch 手动处理异常,不会被ExceptionControllerAdvice 捕获
     *
     * @return
     */
    @GetMapping("/excep4")
    public String exception4() throws SQLException {

        int i = 0;
        if (i == 0) {

            throw new SQLException("sql 语句异常");

        }

        return "exception";
    }
}
